/*
 * Multiphase.h
 *
 *  Created on: 23 Jul 2011
 *      Author: Allan
 */

#ifndef MULTIPHASE_H_
#define MULTIPHASE_H_

// C++ includes
#include <iostream>
#include <memory>
#include <vector>
using namespace std;

// GeoReact includes
#include <Core/Phase.h>
#include <Utils/SpeciesMap.h>
#include <Utils/Types.h>

class Multiphase 
{
public:
	Multiphase();
	
	Multiphase(const vector<Phase>& phases);
	
	const unsigned
	GetNumPhases() const;
	
	const unsigned
	GetNumSpecies() const;
	
	const vector<Phase>&
	GetPhases() const;
	
	const vector<string>&
	GetSpecies() const;
	
	const Index
	FindPhase(const string& phase_name) const;
	
	const Index
	operator[](const string& species) const;
	
	const vector<Index>
	operator[](const vector<string>& species) const;

	const Index
	PhaseIndex(const string& species) const;
	
	const VectorXd
	PhaseMoles(const Index& phase_index, const VectorXd& n) const;
	
	const VectorXd
	TotalMolesPhases(const VectorXd& n) const;
	
	const VectorXd
	ActivityCoefficients(double T, double P, const VectorXd& n) const;
	
	const VectorXd
	Activities(double T, double P, const VectorXd& n) const;
	
	const MatrixXd
	ActivityDerivatives(double T, double P, const VectorXd& n, const VectorXd& a) const;
	
private:
	/// The phases in the multiphase system
	vector<Phase> phases;
	
	/// The union of all the species in the system
	vector<string> species;
	
	/// The species map object that stores the indexes of the species
	SpeciesMap species_map;
	
	/// The species-phase mapping that stores the relationship between species and phase indexes
	map<string, Index> species_to_phase;
};

ostream& operator<<(ostream& out, const Multiphase& multiphase);

#endif /* MULTIPHASE_H_ */
